home *** CD-ROM | disk | FTP | other *** search
/ Programming Sound Cards / Programming Sound Cards.iso / sound_26 / fonetone.asm < prev    next >
Assembly Source File  |  1995-01-01  |  4KB  |  93 lines

  1. code_seg        segment
  2.         assume  cs:code_seg
  3.         org     100h
  4.         jmp     start
  5. ;----------------------------------
  6. ;B/C Software                        ;Author
  7. ;520 North Stateline Rd
  8. ;Sharon, Pa 16146
  9. ;----------------------------------
  10. delay    dw     0                    ;place to store our delay count
  11. message1 db     'press Esc to Quit',0dh,0ah,'$'     ;Esc to end phone_tone
  12. message2 db     'press any other key to play$'      ;or to go again
  13. ;----------------------------------
  14. start   proc    near
  15.         mov     ah,9                 ;DOS function number to print string
  16.         mov     dx,offset message1   ;the message
  17.         int     21h                  ;DOS interrupt
  18.         mov     ah,9                 ;DOS function number to print string
  19.         mov     dx,offset message2   ;the message
  20.         int     21h                  ;DOS interrupt
  21. begin:  mov     ah,0                 ;BIOS function wait for key press
  22.         int     16h                  ;BIOS interrupt
  23.         cmp     ah,1                 ;Esc scan code 
  24.         jz      done                 ;do we stop ?
  25.         call    phone_tone           ;no call phone_tone
  26.         jmp     begin                ;go see if we do it again
  27. done:   mov     ax,4c00h             ;no exit back to DOS
  28.         int     21h                  ;DOS interrupt
  29. start   endp
  30. ;----------------------------------
  31. phone_tone      proc    near
  32.         cli                     ;lets not allow interrupts
  33. go_2:   mov     si,2            ;do the - two six pulse groups - two times
  34. mainx:  mov     di,2            ;do group of six pulses two times
  35. mainy:  mov     dx,6            ;do six pulses of each tone
  36. mainz:  mov     bx,2000         ;frequency of first tone
  37.         call    workman         ;go set timer chip and send (bx) to port
  38.         mov     delay,1         ;place first delay count in (delay)       
  39.         call    delayer         ;wait a bit before next tone
  40.         mov     bx,1600         ;frequency of second tone
  41.         call    workman         ;go set timer chip and send (bx) to port
  42.         mov     delay,1         ;place first delay count in (delay)
  43.         call    delayer         ;wait a bit before next time
  44.         dec     dx              ;decrement pulse count
  45.         jnz     mainz           ;have we done six pulses
  46.         dec     di              ;yes go do second group of six pulses
  47.         jnz     mainy           ;have we done two groups
  48.         in      al,61h          ;yes - turn speaker off  
  49.         and     al,11111100xb   ;this number turns speaker off
  50.         out     61h,al          ;send it to port
  51.         mov     delay,30        ;place second delay count in delay
  52.         call    delayer         ;wait a while  
  53.         dec     si              ;if si not 0
  54.         jnz     mainx           ;go do two more - six pulse - groups
  55.         sti                     ;time to enable interrupts
  56.         ret                     ;go see if user wants to go again
  57. phone_tone      endp
  58. ;----------------------------------
  59. delayer proc    near
  60.         push    ax           ;save these registers
  61.         push    bx
  62.         push    dx
  63.         mov     ah,0         ;want to read time
  64.         int     01ah         ;get initial tick count
  65.         add     dx,delay     ;add our count to tick count  
  66.         mov     bx,dx        ;place it in bx            
  67. delay_it:                  
  68.         int     01ah         ;get reading again
  69.         cmp     dl,bl        ;compare reading to delay count
  70.         jne     delay_it     ;go back and repeat if not equal
  71.         pop     dx
  72.         pop     bx
  73.         pop     ax           ;restore used registers
  74.         ret
  75. delayer endp
  76. ;--------------------------------------
  77. workman proc  near
  78.         mov     al,10110110xb  ;channel 2
  79.         out     43h,al         ;operation mode 3
  80.         mov     ax,bx          ;place freqrency in ax
  81.         out     42h,al         ;send LSB first
  82.         mov     al,ah          ;place MSB in al
  83.         out     42h,al         ;send it next
  84.         in      al,61h         ;get 8255 port contents
  85.         or      al,00000011xb  ;this number turns speaker on
  86.         out     61h,al         ;turn it on now
  87.         ret
  88. workman         endp
  89. ;----------------------------------
  90. code_seg        ends
  91.  
  92.  
  93.